package com.example.lxj.base.exception;

import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;

import com.example.lxj.base.entity.AjaxRes;

/**
 * 自定义全局异常类（阉割版）
 */

@ControllerAdvice
public class GlobalExceptionHandler {
    
    @ExceptionHandler(value = Exception.class)
    public ResponseEntity<AjaxRes> handleAllException(Exception e){
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(AjaxRes.error(e.getMessage()));
    }

    @ExceptionHandler(value = LoginFailedException.class)
    public ResponseEntity<AjaxRes> handleLoginFailedException(Exception e){
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(AjaxRes.error(e.getMessage()));
    }

    @ExceptionHandler(value = BussinessFailedException.class)
    public ResponseEntity<AjaxRes> handleBussinessFailedException(Exception e){
        return ResponseEntity.status(HttpStatus.OK).body(AjaxRes.warn(e.getMessage()));
    }
}
